import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'

const User = () => import(/* webpackChunkName: 'User' */'@/views/User')
const Search = () => import('@/views/Search')
const SearchResultList = () => import('@/views/Search/SearchResultList')
const ArticleDtail = () => import('@/views/Article/id')
const UserEdit = () => import('@/views/User/userEdit')
const Xiaosi = () => import('@/views/Xiaosi')

Vue.use(VueRouter)

const routes = [
  // 一级路由
  // 重定向
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      // 二级路由
      {
        path: 'home',
        component: Home
      },
      {
        path: 'user',
        component: User
      }
    ]
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/search/:name', // 动态路由
    component: SearchResultList
  },
  {
    path: '/article',
    component: ArticleDtail
  },
  {
    path: '/user/edit',
    component: UserEdit
  },
  {
    path: '/xiaosi',
    component: Xiaosi
  }
]

const router = new VueRouter({
  routes
})

export default router
